package com.hyf.zookeeper.core;

import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;
import java.util.concurrent.CountDownLatch;

public class ZKSetData {

    private static ZooKeeper zk;

    private static ZookeeperConnection zkConn;

    public static void update(String path,byte[] data) throws KeeperException, InterruptedException {
        zk.setData(path,data,zk.exists(path,true).getVersion());
    }

    public static void main(String[] args){
        final String path="/MyFirstZnode2";

        final CountDownLatch connectSignal=new CountDownLatch(1);
        zkConn=new ZookeeperConnection();
        try {
            zk=zkConn.connect("47.93.157.178:12181");
            update(path,"success".getBytes());
            System.out.println("end");
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (KeeperException e) {
            e.printStackTrace();
        }
    }
}
